package com.vinobase.model.bean;


import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Unindexed;

import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;


@Entity
@Cached
public class Culture implements Comparable{

    @Id
    private Long id;

    @NotNull
    @Size(min=1, max=25)
    private String name;

    @NotNull
    @Unindexed
    private String displayName;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Culture culture = (Culture) o;

        if (displayName != null ? !displayName.equals(culture.displayName) : culture.displayName != null) return false;
        if (id != null ? !id.equals(culture.id) : culture.id != null) return false;
        if (name != null ? !name.equals(culture.name) : culture.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (displayName != null ? displayName.hashCode() : 0);
        return result;
    }

    public int compareTo(Object o) {
         if(!(o instanceof Culture)){
            return -9999;
        }
        Culture c = (Culture)o;
        int cmp = name.compareTo(c.getName());
        if(cmp==0)
            cmp = displayName.compareTo(c.getDisplayName()) ;
        return cmp;
    }
}
